/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.httpsdk.http.face;

import android.content.Context;
import android.util.Log;

import com.shwread.httpsdk.constant.ResultCode;
import com.shwread.httpsdk.http.base.AbstractHttpPostDracom;
import com.shwread.httpsdk.http.callback.ActionListener;

import org.json.JSONObject;

import java.util.HashMap;

import logic.constants.AppConfig;
import logic.constants.Const;


/**
 * @Project： Lqyd_Android
 * @Title：QryUnReadTotalAction
 * @Description：根据消息来源查询消息未读总数
 * @Author：wayne
 * @Date：2014年8月17日下午2:05:54
 */
public class QryLastUnReadMsgAction
        extends
		AbstractHttpPostDracom
{

	private String writeSource;
	private String lastTimeStamp;
	/**
	 * <p>
	 * Title:
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 *
	 * @param context
	 * @param action
	 * @param actionListener
	 */
	public QryLastUnReadMsgAction(Context context, String writeSource, String lastTimeStamp, ActionListener actionListener) {
		super(context, "qryUnReadTotal.do", actionListener);
		this.writeSource = writeSource;
		this.lastTimeStamp = lastTimeStamp;
	}
	
	@Override
	public void getParameter(HashMap<String, String> parameter_map) {
		parameter_map.put("account", Const.phone_number);
		parameter_map.put("timeStamp", String.valueOf(timeStamp));
		parameter_map.put("lastTimeStamp", lastTimeStamp);
		parameter_map.put("enterpriseId", AppConfig.getEnterpriseId());
		parameter_map.put("writeSource", writeSource);
		parameter_map.put("cid", cid(Const.phone_number + Const.ACCOUNTTYPE + Const.CLIENTTYPE + timeStamp + AppConfig.getEnterpriseId()));
		Log.e("消息参数",parameter_map.toString());
	}
	
	@Override
	public void doResponseXml(String xml) {
		println(xml);
		int result = -1;
		try
		{
			JSONObject jsonObject = new JSONObject(xml);
			result = jsonObject.getInt("resultCode");
			if (result == 1000)
			{
				listener.OK(jsonObject.getJSONObject("returnObject"));
			}
			else
			{
				listener.ERROR(result, ResultCode.getResultText(result));
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	//{"resultCode":1000,"returnObject":{"lastTimeStamp":1477363606938,"msgType":1003}}
	
	@Override
	protected void doRequestHeader(HashMap<String, String> header_map) {
		
	}
	
	@Override
	public void dispose() {
		
	}
	
}
